<template>
  <div class="contrain">
    <HeadTitle :left="true"
               :middle="true"
               :right="true"
               @back="back">
      <template v-slot:middle>
        <h1>编辑帖子</h1>
      </template>
      <template v-slot:right>
        <h2 @click="sendInvi">发布</h2>
      </template>
    </HeadTitle>
    <van-form>
      <van-field v-model.trim="Invi.title"
                 placeholder="请输入标题（5-100字）" />
      <van-field v-model.trim="Invi.main"
                 type="textarea"
                 rows="10"
                 autosize
                 autofocus />
    </van-form>
  </div>
</template>
<script>
import HeadTitle from '_c/utils/HeadTitle.vue'
import { sendInvi } from '@/api/forum'
export default {
  components: { HeadTitle },
  data () {
    return {
      Invi: {
        title: '',
        main: ''
      }
    }
  },
  methods: {
    sendInvi () {
      if (!this.Invi.title || !this.Invi.main) {
        return this.$toast.fail('请将帖子补充完整')
      }
      sendInvi(this.$store.state.User.user._id, this.Invi).then(() => {
        this.$toast.success('发布成功')
        this.$router.push('/forum')
      })
    },
    back () {
      this.$router.push('/forum')
    }
  }
}
</script>

<style lang="less" scoped>
.van-form {
  margin-top: 60px;
}
</style>
